//<SCRIPT LANGUAGE=javascript>
function isIE(){ return document.all?true:false; }
function getSELValue(sel){ return sel[sel.selectedIndex].value; }
function setRADIOValue(radio,value){
var r;
  for(r=0; r < radio.length; r++)
    if( radio[r].value == value ){radio[r].checked=true;return;}
}
function isHidden(e){
var name = e.name;
  return name.substr(0,1) == '__';
}
//************** Persist ***************
//Call this function to persist forms before submition
function persist(f){
  if( !f )f = this;
var frm,frms=document.forms,oForms=new Object();
  for( frm=0; frm < frms.length; frm++ )
    oForms[frms[frm].name] = persistForm(frms[frm]);
  f.__hdnPersist.value = escape(uneval(oForms));
}
function subclassForms(){
  var i,fs = document.forms;
  for( i=0; i < fs.length; i++ ){
    fs[i].OnSubmit = fs[i].onsubmit;
    fs[i].onsubmit = persist;
  }
}
function persistForm(frm){
var v,e,es=frm.elements,i,oForm = new Object();
  for( i=0 ; i < es.length; i++,v=null){
    e = es[i];
    if( isHidden(e) )continue;
    switch(e.type){
      case "select-one":
        v = getSELValue(e);break;
      case "text":
      case "textarea":
      case "hidden":
	    case "password":
        v = e.value.replace(/'/g,"\\'").replace(/"/g,'\\"');break;
      case "checkbox":
        v = e.checked;break;
      case "radio":
        if(e.checked)v = e.value;break;
    }
    if(v != null) new ELEMENT(e.name,e.type,v,oForm);
  }
  return oForm;
}
function getElementValue(e){
  switch(e.type){
    case "select-one":
      return getSELValue(e);
    case "text":
    case "textarea":
    case "hidden":
    case "password":
      return e.value.replace(/'/g,"\\'").replace(/"/g,'\\"');
    case "checkbox":
      return e.checked?e.value:"";
    case "radio":
      e.checked?e.value:null;
  }
  return null;
}
function ELEMENT(name,type,value,elements){
  this.name = name;
  this.type = type;
  this.value = value;
  if(!elements[name]){
    elements[name] = new Object();
    elements[name].info = {type:type,name:name};
    elements[name].values = new Array();
  }
  elements[name].values[elements[name].values.length] = value;
}
//*********** Restore **************
//Call this function to restore forms after loading
function restore(hdnPersist) {
  if( typeof(hdnPersist) == 'undefined' )return;
var f;
  for( f in hdnPersist)
    restoreForm(hdnPersist[f],f);
}
function restoreForm(frm,name){
var es;
  for( es in frm )
   if( document.forms[name] )
		restoreElements(frm[es],document.forms[name][es]);
}
function restoreElements(es,fes){
  if( !fes )return;
  var e;
  if( fes.type )
    restoreElement(es.values[0],fes);
  else
    for( e=0; e < fes.length; e++ )
      restoreElement(isRadio(fes[e])?es.values[0]:es.values[e],fes[e]);
}
function restoreElement(e,fe){
	if( !fe.type )
		for(var i=0; i < fe.length; i++ )
			restoreElement(e,fe[i]);
		else
			switch(fe.type){
			  case "select-one": 
			    setSELValue(fe,e);break;
			  case "text":
			  case "textarea":
			  case "hidden":
			  case "password":
			    fe.value = e;break;
			  case "checkbox":
			    fe.checked = e;break;
			  case "radio":
			    fe.checked = (e==fe.value);
			}
}
function isRadio(e){
  return e.type == "radio";
}
